'use strict';

const path = require('path');
const fs = require('mz/fs');

module.exports = appInfo => {
  const config = exports = {};

  /**
    * Static file serve
    *
    * @member Config#static
    * @property {String} prefix - `/public/` by default
    * @property {String} dir - static files store dir, `${baseDir}/app/public` by default
    * @property {Number} maxAge - cache max age, default is 0
    * @see https://github.com/koajs/static-cache
    */
  config.static = {
    prefix: '/',
    dir: [path.join(appInfo.baseDir, 'app/public'), path.join(appInfo.baseDir, 'uploadFiles'), { prefix: '/c3fc7resource/', dir: path.join(appInfo.baseDir, 'uploadFiles/upload') }],
    // dirs: [ dir1, dir2 ] or [ dir1, { prefix: '/static2', dir: dir2 } ],
    // support lazy load
    dynamic: true,
    preload: false,
    buffer: false,
    maxFiles: 1000,
  };

  config.siteFile = {
    '/favicon.ico': fs.readFileSync(path.join(appInfo.baseDir, 'app/public/favicon.ico')),
  };

  config.security = {
    csrf: {
      enable: false,
    },
  };


  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_{{keys}}';

  // add your config here
  config.middleware = [];

  // change to your own sequelize configurations
  config.sequelize = {
    dialect: 'sqlite',
    storage: 'database/database.sqlite',
    pool: {
      max: 5,
      min: 0,
      acquire: 30000,
      idle: 10000,
    },
    define: {
      timestamps: false, // 去除createAt updateAt
      underscored: true, // 注意需要加上这个， egg-sequelize只是简单的使用Object.assign对配置和默认配置做了merge, 如果不加这个 update_at会被转变成 updateAt故报错
      // 禁止修改表名，默认情况下，sequelize将自动将所有传递的模型名称（define的第一个参数）转换为复数
      // 但是为了安全着想，复数的转换可能会发生变化，所以禁止该行为
      freezeTableName: true,
    },
    operatorsAliases: false,
    dialectOptions: {
      dateStrings: true,
      typeCast: true,
    },
    //   dialect: 'mysql',
    //   host: 'localhost',
    //   port: 3306,
    //   database: 'egg-sequelize-default',
    //   username: 'root',
    //   password: '',

  };


  return config;
};
